<!doctype html>
<html lang="en">
<head>
  <title>Sse测试文档</title>
</head>
<body>
<div>sse测试</div>
<div id="result"></div>
</body>
</html>
<script>
  var source = new EventSource('http://localhost:8092/sse/subscribe?id=yihuihui');
  source.onmessage = function (event) {
    text = document.getElementById('result').innerText;
    text += '\n' + event.data;
    document.getElementById('result').innerText = text;
  };
  <!-- 添加一个开启回调 -->
  source.onopen = function (event) {
    text = document.getElementById('result').innerText;
    text += '\n 开启: ';
    console.log(event);
    document.getElementById('result').innerText = text;
  };
</script>